import axios from 'axios'
import storage from '@/storage'

// ajax 请求全局配置 common/get/post
const ajax = axios.create({
  timeout: 10000,
  header: {
    'Content-Type': 'application/json'
  },
  transformRequest: [],
  transformResponse: [],
  validateStatus: function (status) {
    return status >= 200 && status < 300 // default
  }
})

// 拦截请求
ajax.interceptors.request.use(function (config) {
  config.headers['Authorization'] = storage.get('AUTH_TOKEN') || ''
  return config
}, function (error) {
  return Promise.reject(error)
})

// 拦截响应
ajax.interceptors.response.use(function (config) {
  return config
}, function (error) {
  return Promise.reject(error)
})

export default ajax
